class Physical {
    constructor(game) {
        this.game = game
        this.setUp()
    }

    static new = function(game) {
        return new Physical(game)
    }

    setUp() {
        this.balls = []
        this.setPosition(20, 20)

    }

    addElement(element) {
        this.balls.push(element)
        this.scene.addElement(element)
    }

    draw() {
        for (var i = 0; i < this.balls.length; i++) {
            var p = this.balls[i]
            p.draw()
        }
    }


    update() {
        for (var i = 0; i < this.balls.length; i++) {
            var p = this.balls[i]
            p.update()
        }

        this.balls = this.balls.filter(p => p.alive)
    }

    setPosition(x, y) {
        this.x = x
        this.y = y
    }
}

class Ball {
    constructor(game) {
        this.game = game
        this.setUp()
    }
    static new = function(game) {
        var i = new this(game)
        return i
    }

    setUp() {
        this.name = 'ball'
        this.image = GuaImage.new(this.game, 'ball')
        this.life = 1000000
        this.coolDown = 60
        this.cool = this.coolDown
        this.alive = true

    }

    fired() {
        if (this.life == 0) {
            this.alive = false
        }
        this.life--
    }

    init(x, y, vx, vy, ax, ay) {
        this.image.setPosition(x, y)
        this.ax = ax / 60
        this.ay = ay / 60
        this.vx = vx / 60
        this.vy = vy / 60
    }

    move() {
        this.image.x += this.vx
        this.image.y += this.vy
    }

    draw() {
        if (this.alive) {
            this.image.draw()
        }
    }

    update() {
        log("this.ax", this.ax)
        log("this.ay", this.ay)
        log("this.vy", this.vy)
        log("this.vx", this.vx)
        this.move()

        this.vx += this.ax
        this.vy += this.ay



    }

}